﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NPOI.XWPF.UserModel;
using System.IO;
using NPOI.OpenXmlFormats.Wordprocessing;
using System.Drawing;
using Novacode;
using System.Globalization;
using System.Drawing.Imaging;

namespace ProjectStudy
{
    public partial class NPOI生成word : System.Web.UI.Page
    {
        private static Border BlankBorder = new Border(Novacode.BorderStyle.Tcbs_single, 0, 0, Color.Black);
        protected void Page_Load(object sender, EventArgs e)
        {
            //新建一个Word文档，加载Load的方法和Create使用一样。
            using (DocX document = DocX.Create(@"C://PDF/Test.docx"))
            {
                //添加一些基本对象，如段落等
                //首先创建1个格式对象
                Formatting formatting = new Formatting();
                formatting.Bold = true;
                formatting.FontColor = Color.Red;
                formatting.Size = 20;

                Paragraph p = document.InsertParagraph();
                //设置段落样式
                p.Append("Hello World!^011Hello World!")
                .Font(new FontFamily("Times New Roman"))
                .FontSize(32)
                .Color(Color.Blue)
                .Bold();

                p.Append("我会").Append("加粗").Bold()
                .Append("并且我会")
                .Append("斜体").Italic().Append(".")
                .AppendLine("我换行啦，")
                .Append("这是华文彩云字体")
                .Font(new FontFamily("华文彩云"))
                .AppendLine("我又换行啦， ")
                .Append("蓝色字体").Color(Color.Blue)
                .Append("后面是红色字体")
                .Append("红色字体").Color(Color.Red).Append(".");

                //两个段落在一个页面显示
                p.KeepWithNext();
                
                document.InsertParagraph("上一个段落将会和这个段落在同一页显示");

                //一个段落在一个页面显示(禁止分页)
                Paragraph p2 = document.InsertParagraph("所有行将会在同一个页面...\n第2行\n第3行\n第4行\n第5行\n第6行...");
                p2.KeepLinesTogether();

                //给文档新建1个段落对象
                Paragraph p3 = document.InsertParagraph("这是一个段落", false, formatting);

                //添加表格
                var tbl = document.InsertTable(2, 6);
                var wholeWidth = document.PageWidth - document.MarginLeft - document.MarginRight;
                var colWidth = wholeWidth / tbl.ColumnCount;
                tbl.AutoFit = AutoFit.Contents;
                var r = tbl.Rows[0];

                var cx = 0;
                foreach (var cell in r.Cells)
                {
                    cell.Paragraphs.First().Append("第" + (cx + 1) + "列");
                    cell.Paragraphs.First().Alignment = Alignment.center;//单元格内容居中
                    cell.Width = colWidth;//设置单元格列宽
                    cell.MarginBottom = 0;
                    cell.MarginLeft = 0;
                    cell.MarginRight = 0;
                    cell.MarginTop = 0;

                    cx++;
                }
                tbl.SetBorder(TableBorderType.Bottom, BlankBorder);
                tbl.SetBorder(TableBorderType.Left, BlankBorder);
                tbl.SetBorder(TableBorderType.Right, BlankBorder);
                tbl.SetBorder(TableBorderType.Top, BlankBorder);
                tbl.SetBorder(TableBorderType.InsideV, BlankBorder);
                tbl.SetBorder(TableBorderType.InsideH, BlankBorder);

                //添加图片1
                Novacode.Image image = document.AddImage(Server.MapPath(@"images/Image.jpg"));
                Picture picture = image.CreatePicture();
                picture.Width = 200;
                picture.Height = 200;
                //picture.Rotation = 10;//图片旋转
                picture.SetPictureShape(BasicShapes.heart);//设置图片样式

                Paragraph title = document.InsertParagraph().Append("这是一个普通段落").FontSize(20).Font(new FontFamily("黑体"));
                title.Alignment = Alignment.center;

                Paragraph p1 = document.InsertParagraph();

                p1.AppendLine("这个段落下面的文字会紧跟着上面的图片");
                p1.AppendLine();
                p1.AppendLine("紧跟着上面的图片（左侧）").AppendPicture(picture).Append("紧跟着上面的图片（右侧）");
                p1.AppendLine();

                //添加图片2
                Picture pictureNormal = image.CreatePicture();
                pictureNormal.Width = 100;
                pictureNormal.Height = 100;
                Paragraph p4 = document.InsertParagraph();
                p4.AppendLine("这是一个在段落中的普通图片");
                p4.AppendPicture(pictureNormal);

                //var h1 = document.InsertParagraph("Heading 1");
                //h1.StyleName = "Heading1";
                //document.InsertParagraph("Some very interesting content here");
                //var h2 = document.InsertParagraph("Heading 2");
                //document.InsertSectionPageBreak();
                //h2.StyleName = "Heading1";
                //document.InsertParagraph("Some very interesting content here as well");
                //var h3 = document.InsertParagraph("Heading 2.1");
                //h3.StyleName = "Heading2";
                //document.InsertParagraph("Not so very interesting....");
                //document.InsertTableOfContents(h2, "I can haz table of contentz", TableOfContentsSwitches.O | TableOfContentsSwitches.U | TableOfContentsSwitches.Z | TableOfContentsSwitches.H, "Heading2");

                document.Save();//保存

                //设置文档只读
                EditRestrictions erReadOnly = EditRestrictions.readOnly;
                document.AddProtection(erReadOnly, "123");
                //document.SaveAs(@"C://PDF/hasPwd.docx");

                //设置档案允许注释(批注)
                EditRestrictions erComments = EditRestrictions.comments;
                document.AddProtection(erComments, "123");
                //document.SaveAs(@"C://PDF/comment.docx");

                //设置文档
                EditRestrictions erForms = EditRestrictions.forms;
                document.AddProtection(erForms, "123");
                //document.SaveAs(@"C://PDF/form.docx");

                //设置文档
                EditRestrictions erTrackedChanges = EditRestrictions.trackedChanges;
                document.AddProtection(erTrackedChanges, "123");
                //document.SaveAs(@"C://PDF/trackChange.docx");
            }

            DocX doc2 = DocX.Create(@"C://PDF/Template.docx");

            // Create a table for layout purposes (This table will be invisible).
            Novacode.Table layout_table = doc2.InsertTable(2, 2);
            layout_table.Design = TableDesign.TableNormal;
            layout_table.AutoFit = AutoFit.Window;

            // Dark formatting
            Formatting dark_formatting = new Formatting();
            dark_formatting.Bold = true;
            dark_formatting.Size = 12;
            dark_formatting.FontColor = Color.FromArgb(31, 73, 125);

            // Light formatting
            Formatting light_formatting = new Formatting();
            light_formatting.Italic = true;
            light_formatting.Size = 11;
            light_formatting.FontColor = Color.FromArgb(79, 129, 189);

            #region Company Name
            // Get the upper left Paragraph in the layout_table.
            Paragraph upper_left_paragraph = layout_table.Rows[0].Cells[0].Paragraphs[0];

            // Create a custom property called company_name
            CustomProperty company_name = new CustomProperty("company_name", "公司名称");

            // Insert a field of type doc property (This will display the custom property 'company_name')
            layout_table.Rows[0].Cells[0].Paragraphs[0].InsertDocProperty(company_name, f: dark_formatting);

            // Force the next text insert to be on a new line.
            upper_left_paragraph.InsertText("\n", false);
            #endregion

            #region Company Slogan
            // Create a custom property called company_slogan
            CustomProperty company_slogan = new CustomProperty("company_slogan", "公司口号");

            // Insert a field of type doc property (This will display the custom property 'company_slogan')
            upper_left_paragraph.InsertDocProperty(company_slogan, f: light_formatting);
            #endregion

            #region Company Logo
            // Get the upper right Paragraph in the layout_table.
            Paragraph upper_right_paragraph = layout_table.Rows[0].Cells[1].Paragraphs[0];

            // Add a template logo image to this document.

            Novacode.Image logo = doc2.AddImage(Server.MapPath( @"images/Image.jpg"));
            

            // Insert this template logo into the upper right Paragraph.
            Picture pic = logo.CreatePicture();
            pic.Width = 100;
            pic.Height = 100;
            upper_right_paragraph.InsertPicture(pic);

            upper_right_paragraph.Alignment = Alignment.right;
            #endregion

            // Custom properties cannot contain newlines, so the company address must be split into 3 custom properties.
            #region Hired Company Address
            // Create a custom property called company_address_line_one
            CustomProperty hired_company_address_line_one = new CustomProperty("hired_company_address_line_one", "公司地址");

            // Get the lower left Paragraph in the layout_table. 
            Paragraph lower_left_paragraph = layout_table.Rows[1].Cells[0].Paragraphs[0];
            lower_left_paragraph.InsertText("地址:\n", false, dark_formatting);

            // Insert a field of type doc property (This will display the custom property 'hired_company_address_line_one')
            lower_left_paragraph.InsertDocProperty(hired_company_address_line_one, f: light_formatting);

            // Force the next text insert to be on a new line.
            lower_left_paragraph.InsertText("\n", false);

            // Create a custom property called company_address_line_two
            CustomProperty hired_company_address_line_two = new CustomProperty("hired_company_address_line_two", "城市");

            // Insert a field of type doc property (This will display the custom property 'hired_company_address_line_two')
            lower_left_paragraph.InsertDocProperty(hired_company_address_line_two, f: light_formatting);

            // Force the next text insert to be on a new line.
            lower_left_paragraph.InsertText("\n", false);

            // Create a custom property called company_address_line_two
            CustomProperty hired_company_address_line_three = new CustomProperty("hired_company_address_line_three", "邮编000000");

            // Insert a field of type doc property (This will display the custom property 'hired_company_address_line_three')
            lower_left_paragraph.InsertDocProperty(hired_company_address_line_three, f: light_formatting);
            #endregion

            #region Date & Invoice number
            // Get the lower right Paragraph from the layout table.
            Paragraph lower_right_paragraph = layout_table.Rows[1].Cells[1].Paragraphs[0];

            CustomProperty invoice_date = new CustomProperty("invoice_date", DateTime.Today.Date.ToString("d"));
            lower_right_paragraph.InsertText("日期: ", false, dark_formatting);
            lower_right_paragraph.InsertDocProperty(invoice_date, f: light_formatting);

            CustomProperty invoice_number = new CustomProperty("invoice_number", 1);
            lower_right_paragraph.InsertText("\nInvoice: ", false, dark_formatting);
            lower_right_paragraph.InsertText("#", false, light_formatting);
            lower_right_paragraph.InsertDocProperty(invoice_number, f: light_formatting);

            lower_right_paragraph.Alignment = Alignment.right;
            #endregion

            // Insert an empty Paragraph between two Tables, so that they do not touch.
            doc2.InsertParagraph(string.Empty, false);

            // This table will hold all of the invoice data.
            Novacode.Table invoice_table = doc2.InsertTable(4, 4);
            invoice_table.Design = TableDesign.LightShadingAccent1;
            invoice_table.Alignment = Alignment.center;

            // A nice thank you Paragraph.
            Paragraph thankyou = doc2.InsertParagraph("\nThank you for your business, we hope to work with you again soon.", false, dark_formatting);
            thankyou.Alignment = Alignment.center;

            #region Hired company details
            CustomProperty hired_company_details_line_one = new CustomProperty("hired_company_details_line_one", "公司地址, 城市, 邮编");
            CustomProperty hired_company_details_line_two = new CustomProperty("hired_company_details_line_two", "电话: 000-000-0000, 传真: 000-000-0000, 邮箱: support@companyname.com");

            Paragraph companyDetails = doc2.InsertParagraph(string.Empty, false);
            companyDetails.InsertDocProperty(hired_company_details_line_one, f: light_formatting);
            companyDetails.InsertText("\n", false);
            companyDetails.InsertDocProperty(hired_company_details_line_two, f: light_formatting);
            companyDetails.Alignment = Alignment.center;
            #endregion
            doc2.Save();


            using (DocX document = DocX.Load(@"C://PDF/Test2.docx"))
            {
                document.ReplaceText("apple", "APPLE");//替代指定文本

                //在图片上绘制文字
                if (document.Images.Count() > 0)
                {
                    Novacode.Image img = document.Images[0];

                    Bitmap b = new Bitmap(img.GetStream(FileMode.Open, FileAccess.ReadWrite));

                    Graphics g = Graphics.FromImage(b);

                    //开始绘制文字
                    g.DrawString
                    (
                        "你好世界",
                        new Font("宋体", 100),
                        Brushes.Blue,
                        new PointF(0, 0)
                    );
                    //保存图片
                    b.Save(img.GetStream(FileMode.Create, FileAccess.Write), ImageFormat.Jpeg);
                }
                //保存文档
                document.Save();
            }
        }

        //生成模板
        protected void Button1_Click(object sender, EventArgs e)
        {
            DocX doc = DocX.Create(@"C://PDF/JianLi.docx");
            CustomProperty name = new CustomProperty("name", "张三");
            CustomProperty job_intension = new CustomProperty("job_intension", "前端工程师");
            
            Formatting format = new Formatting();
            format.Bold = true;
            format.Size = 22;
            format.FontColor = Color.FromArgb(21, 151, 246);

            Novacode.Table tb1 = doc.InsertTable(3,3);
            float[] widths = { 300,100,200};
            
            tb1.SetWidths(widths);
            Paragraph p1=tb1.Rows[0].Cells[0].InsertParagraph();

            //Paragraph p1 = doc.InsertParagraph();
            p1.AppendDocProperty(name, f: format);
            format.Size = 8;
            //format.Spacing = 10;//字间距
            p1.InsertText("    求职意向:", false, format);
            p1.AppendDocProperty(job_intension, f: format);
            p1.Alignment = Alignment.left;

            p1 = tb1.Rows[0].Cells[2].InsertParagraph();
            
            Novacode.Image logo = doc.AddImage(Server.MapPath(@"images/Image.jpg"));


            // Insert this template logo into the upper right Paragraph.
            Picture pic = logo.CreatePicture();
            pic.Width = 100;
            pic.Height = 150;
            p1.AppendPicture(pic);
            p1.Alignment = Alignment.right;
            //Paragraph p2 = new Paragraph();           
            
            doc.Save();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            DocX template=DocX.Load("C://PDF/Template.docx");
            Paragraph logo_paragraph = template.Tables[0].Rows[0].Cells[1].Paragraphs[0];
            // Remove the template Picture that is in this Paragraph.
            logo_paragraph.Pictures[0].Remove();

            Novacode.Image logo = template.AddImage(Server.MapPath( @"images/Image.jpg"));

            // Insert the Happy Builders logo into this Paragraph.
            Picture pic = logo.CreatePicture();
            pic.Width = 100;
            pic.Height = 150;
            logo_paragraph.InsertPicture(pic);

            // Set the value of the custom property 'company_name'.
            template.AddCustomProperty(new CustomProperty("company_name", "小米科技有限公司"));

            // Set the value of the custom property 'company_slogan'.
            template.AddCustomProperty(new CustomProperty("company_slogan", "小米，为发烧而生"));

            // Set the value of the custom properties 'hired_company_address_line_one', 'hired_company_address_line_two' and 'hired_company_address_line_three'.
            template.AddCustomProperty(new CustomProperty("hired_company_address_line_one", "北京中关村"));
            template.AddCustomProperty(new CustomProperty("hired_company_address_line_two", "北京"));
            template.AddCustomProperty(new CustomProperty("hired_company_address_line_three", "12345"));

            // Set the value of the custom property 'invoice_date'.
            template.AddCustomProperty(new CustomProperty("invoice_date", DateTime.Today.Date.ToString("d")));

            // Set the value of the custom property 'invoice_number'.
            template.AddCustomProperty(new CustomProperty("invoice_number", 1));

            // Set the value of the custom property 'hired_company_details_line_one' and 'hired_company_details_line_two'.
            template.AddCustomProperty(new CustomProperty("hired_company_details_line_one", "中关村, 北京, 12345"));
            template.AddCustomProperty(new CustomProperty("hired_company_details_line_two", "电话: 012-345-6789, 传真: 012-345-6789, e-mail: support@xiaomi.com"));
            template.SaveAs("C://PDF/1.docx");
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            using (DocX document = DocX.Create(@"C://PDF/CeateTableWithTextDirection.docx"))
            {
                // Add a Table to this document.
                Novacode.Table t = document.AddTable(2, 3);
                // Specify some properties for this Table.
                t.Alignment = Alignment.center;
                t.Design = TableDesign.MediumGrid1Accent2;
                // Add content to this Table.
                t.Rows[0].Cells[0].Paragraphs.First().Append("A");
                t.Rows[0].Cells[0].TextDirection = TextDirection.btLr;
                t.Rows[0].Cells[1].Paragraphs.First().Append("B");
                t.Rows[0].Cells[1].TextDirection = TextDirection.right;
                t.Rows[0].Cells[2].Paragraphs.First().Append("C");
                t.Rows[0].Cells[2].TextDirection = TextDirection.btLr;
                t.Rows[1].Cells[0].Paragraphs.First().Append("D");
                t.Rows[1].Cells[1].Paragraphs.First().Append("E");
                t.Rows[1].Cells[2].Paragraphs.First().Append("F");
                // Insert the Table into the document.
                document.InsertTable(t);
                document.Save();
            }// Release this document from memory.
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            using (DocX document = DocX.Create(@"C://PDF/HeadersAndFootersWithImagesAndTablesUsingInsertPicture.docx"))
            {
                // Add a template logo image to this document.
                Novacode.Image logo = document.AddImage(Server.MapPath( @"images/Image.jpg"));

                // Add Headers and Footers to this document.
                document.AddHeaders();
                document.AddFooters();

                // Force the first page to have a different Header and Footer.
                document.DifferentFirstPage = false;

                // Force odd & even pages to have different Headers and Footers.
                document.DifferentOddAndEvenPages = true;

                // Get the first, odd and even Headers for this document.
                Header header_first = document.Headers.first;
                Header header_odd = document.Headers.odd;
                Header header_even = document.Headers.even;

                // Get the first, odd and even Footer for this document.
                Footer footer_first = document.Footers.first;
                
                Footer footer_odd = document.Footers.odd;
                Footer footer_even = document.Footers.even;

                // Insert a Paragraph into the first Header.
                Paragraph p0 = header_first.InsertParagraph();
                p0.Append("这是首页页眉").Bold();
                p0.Alignment = Alignment.center;


                // Insert a Paragraph into the odd Header.
                Paragraph p1 = header_odd.InsertParagraph();
                p1.Append("这是奇数页眉").Bold();
                p1.Alignment = Alignment.center;


                // Insert a Paragraph into the even Header.
                Paragraph p2 = header_even.InsertParagraph();
                p2.Append("这是偶数页眉").Bold();
                p2.Alignment = Alignment.center;

                // Insert a Paragraph into the first Footer.
                Paragraph p3 = footer_first.InsertParagraph();                
                p3.Append("这是首页页脚").Bold();
                p3.Alignment = Alignment.center;

                // Insert a Paragraph into the odd Footer.
                Paragraph p4 = footer_odd.InsertParagraph();
                p4.Append("这是奇数页脚").Bold();
                p4.Alignment = Alignment.center;
                PageNumberFormat pf = new PageNumberFormat();
                
                p4.InsertPageNumber(pf);

                // Insert a Paragraph into the even Header.
                Paragraph p5 = footer_even.InsertParagraph();
                p5.Append("这是偶数页脚").Bold();
                p5.Alignment = Alignment.center;

                // Insert a Paragraph into the document.
                Paragraph p6 = document.InsertParagraph();
                p6.AppendLine("这是第一页");

                // Create a second page to show that the first page has its own header and footer.
                p6.InsertPageBreakAfterSelf();

                // Insert a Paragraph after the page break.
                Paragraph p7 = document.InsertParagraph();
                p7.AppendLine("这是第二页");

                // Create a third page to show that even and odd pages have different headers and footers.
                p7.InsertPageBreakAfterSelf();

                // Insert a Paragraph after the page break.
                Paragraph p8 = document.InsertParagraph();
                p8.AppendLine("这是第三页");

                //Insert a next page break, which is a section break combined with a page break
                document.InsertSectionPageBreak();

                //Insert a paragraph after the "Next" page break
                Paragraph p9 = document.InsertParagraph();
                p9.Append("Next page section break.");

                //Insert a continuous section break
                document.InsertSection();

                //Create a paragraph in the new section
                var p10 = document.InsertParagraph();
                p10.Append("Continuous section paragraph.");


                // Inserting logo into footer and header into Tables

                #region Company Logo in Header in Table
                // Insert Table into First Header - Create a new Table with 2 columns and 1 rows.
                Novacode.Table header_first_table = header_first.InsertTable(1, 2);
                header_first_table.Design = TableDesign.TableGrid;
                header_first_table.AutoFit = AutoFit.Window;
                // Get the upper right Paragraph in the layout_table.
                Paragraph upperRightParagraph = header_first.Tables[0].Rows[0].Cells[1].Paragraphs[0];
                // Insert this template logo into the upper right Paragraph of Table.

                Picture pic = logo.CreatePicture();
                pic.Width = 100;
                pic.Height = 100;
                upperRightParagraph.InsertPicture(pic);
                upperRightParagraph.Alignment = Alignment.right;

                // Get the upper left Paragraph in the layout_table.
                Paragraph upperLeftParagraphFirstTable = header_first.Tables[0].Rows[0].Cells[0].Paragraphs[0];
                upperLeftParagraphFirstTable.Append("Company Name - DocX Corporation");
                #endregion


                #region Company Logo in Header in Invisible Table
                // Insert Table into First Header - Create a new Table with 2 columns and 1 rows.
                Novacode.Table header_second_table = header_odd.InsertTable(1, 2);
                header_second_table.Design = TableDesign.None;
                header_second_table.AutoFit = AutoFit.Window;
                // Get the upper right Paragraph in the layout_table.
                Paragraph upperRightParagraphSecondTable = header_second_table.Rows[0].Cells[1].Paragraphs[0];
                // Insert this template logo into the upper right Paragraph of Table.
                upperRightParagraphSecondTable.InsertPicture(logo.CreatePicture());
                upperRightParagraphSecondTable.Alignment = Alignment.right;

                // Get the upper left Paragraph in the layout_table.
                Paragraph upperLeftParagraphSecondTable = header_second_table.Rows[0].Cells[0].Paragraphs[0];
                upperLeftParagraphSecondTable.Append("Company Name - DocX Corporation");
                #endregion

                #region Company Logo in Footer in Table
                // Insert Table into First Header - Create a new Table with 2 columns and 1 rows.
                Novacode.Table footer_first_table = footer_first.InsertTable(1, 2);
                footer_first_table.Design = TableDesign.TableGrid;
                footer_first_table.AutoFit = AutoFit.Window;
                // Get the upper right Paragraph in the layout_table.
                Paragraph upperRightParagraphFooterParagraph = footer_first.Tables[0].Rows[0].Cells[1].Paragraphs[0];
                // Insert this template logo into the upper right Paragraph of Table.
                upperRightParagraphFooterParagraph.InsertPicture(logo.CreatePicture());
                upperRightParagraphFooterParagraph.Alignment = Alignment.right;

                // Get the upper left Paragraph in the layout_table.
                Paragraph upperLeftParagraphFirstTableFooter = footer_first.Tables[0].Rows[0].Cells[0].Paragraphs[0];
                upperLeftParagraphFirstTableFooter.Append("Company Name - DocX Corporation");
                #endregion



                #region Company Logo in Header in Invisible Table
                // Insert Table into First Header - Create a new Table with 2 columns and 1 rows.
                Novacode.Table footer_second_table = footer_odd.InsertTable(1, 2);
                footer_second_table.Design = TableDesign.None;
                footer_second_table.AutoFit = AutoFit.Window;
                // Get the upper right Paragraph in the layout_table.
                Paragraph upperRightParagraphSecondTableFooter = footer_second_table.Rows[0].Cells[1].Paragraphs[0];
                // Insert this template logo into the upper right Paragraph of Table.
                upperRightParagraphSecondTableFooter.InsertPicture(logo.CreatePicture());
                upperRightParagraphSecondTableFooter.Alignment = Alignment.right;

                // Get the upper left Paragraph in the layout_table.
                Paragraph upperLeftParagraphSecondTableFooter = footer_second_table.Rows[0].Cells[0].Paragraphs[0];
                upperLeftParagraphSecondTableFooter.Append("Company Name - DocX Corporation");
                #endregion

                // Save all changes to this document.
                document.Save();

            }// Release this document from memory.
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            using (DocX document = DocX.Create(@"C://PDF/HeadersAndFootersWithImagesAndTables.docx"))
            {
                Novacode.Image logo = document.AddImage(Server.MapPath( @"images/Image.jpg"));

                // Add Headers and Footers to this document.
                document.AddHeaders();
                document.AddFooters();

                // Force the first page to have a different Header and Footer.
                document.DifferentFirstPage = true;

                // Force odd & even pages to have different Headers and Footers.
                document.DifferentOddAndEvenPages = true;

                // Get the first, odd and even Headers for this document.
                Header header_first = document.Headers.first;
                Header header_odd = document.Headers.odd;
                Header header_even = document.Headers.even;

                // Get the first, odd and even Footer for this document.
                Footer footer_first = document.Footers.first;
                Footer footer_odd = document.Footers.odd;
                Footer footer_even = document.Footers.even;

                // Insert a Paragraph into the first Header.
                Paragraph p0 = header_first.InsertParagraph();
                p0.Append("Hello First Header.").Bold();



                // Insert a Paragraph into the odd Header.
                Paragraph p1 = header_odd.InsertParagraph();
                p1.Append("Hello Odd Header.").Bold();


                // Insert a Paragraph into the even Header.
                Paragraph p2 = header_even.InsertParagraph();
                p2.Append("Hello Even Header.").Bold();

                // Insert a Paragraph into the first Footer.
                Paragraph p3 = footer_first.InsertParagraph();
                p3.Append("Hello First Footer.").Bold();

                // Insert a Paragraph into the odd Footer.
                Paragraph p4 = footer_odd.InsertParagraph();
                p4.Append("Hello Odd Footer.").Bold();

                // Insert a Paragraph into the even Header.
                Paragraph p5 = footer_even.InsertParagraph();
                p5.Append("Hello Even Footer.").Bold();

                // Insert a Paragraph into the document.
                Paragraph p6 = document.InsertParagraph();
                p6.AppendLine("Hello First page.");

                // Create a second page to show that the first page has its own header and footer.
                p6.InsertPageBreakAfterSelf();

                // Insert a Paragraph after the page break.
                Paragraph p7 = document.InsertParagraph();
                p7.AppendLine("Hello Second page.");

                // Create a third page to show that even and odd pages have different headers and footers.
                p7.InsertPageBreakAfterSelf();

                // Insert a Paragraph after the page break.
                Paragraph p8 = document.InsertParagraph();
                p8.AppendLine("Hello Third page.");

                //Insert a next page break, which is a section break combined with a page break
                document.InsertSectionPageBreak();

                //Insert a paragraph after the "Next" page break
                Paragraph p9 = document.InsertParagraph();
                p9.Append("Next page section break.");

                //Insert a continuous section break
                document.InsertSection();

                //Create a paragraph in the new section
                var p10 = document.InsertParagraph();
                p10.Append("Continuous section paragraph.");


                // Inserting logo into footer and header into Tables

                #region Company Logo in Header in Table
                // Insert Table into First Header - Create a new Table with 2 columns and 1 rows.
                Novacode.Table header_first_table = header_first.InsertTable(1, 2);
                header_first_table.Design = TableDesign.TableGrid;
                header_first_table.AutoFit = AutoFit.Window;
                // Get the upper right Paragraph in the layout_table.
                Paragraph upperRightParagraph = header_first.Tables[0].Rows[0].Cells[1].Paragraphs[0];
                // Insert this template logo into the upper right Paragraph of Table.
                upperRightParagraph.AppendPicture(logo.CreatePicture());
                upperRightParagraph.Alignment = Alignment.right;

                // Get the upper left Paragraph in the layout_table.
                Paragraph upperLeftParagraphFirstTable = header_first.Tables[0].Rows[0].Cells[0].Paragraphs[0];
                upperLeftParagraphFirstTable.Append("Company Name - DocX Corporation");
                #endregion


                #region Company Logo in Header in Invisible Table
                // Insert Table into First Header - Create a new Table with 2 columns and 1 rows.
                Novacode.Table header_second_table = header_odd.InsertTable(1, 2);
                header_second_table.Design = TableDesign.None;
                header_second_table.AutoFit = AutoFit.Window;
                // Get the upper right Paragraph in the layout_table.
                Paragraph upperRightParagraphSecondTable = header_second_table.Rows[0].Cells[1].Paragraphs[0];
                // Insert this template logo into the upper right Paragraph of Table.
                Picture pic = logo.CreatePicture();
                pic.Width = 100;
                pic.Height = 100;
                upperRightParagraphSecondTable.AppendPicture(pic);
                upperRightParagraphSecondTable.Alignment = Alignment.right;

                // Get the upper left Paragraph in the layout_table.
                Paragraph upperLeftParagraphSecondTable = header_second_table.Rows[0].Cells[0].Paragraphs[0];
                upperLeftParagraphSecondTable.Append("Company Name - DocX Corporation");
                #endregion

                #region Company Logo in Footer in Table
                // Insert Table into First Header - Create a new Table with 2 columns and 1 rows.
                Novacode.Table footer_first_table = footer_first.InsertTable(1, 2);
                footer_first_table.Design = TableDesign.TableGrid;
                footer_first_table.AutoFit = AutoFit.Window;
                // Get the upper right Paragraph in the layout_table.
                Paragraph upperRightParagraphFooterParagraph = footer_first.Tables[0].Rows[0].Cells[1].Paragraphs[0];
                // Insert this template logo into the upper right Paragraph of Table.
                upperRightParagraphFooterParagraph.AppendPicture(logo.CreatePicture());
                upperRightParagraphFooterParagraph.Alignment = Alignment.right;

                // Get the upper left Paragraph in the layout_table.
                Paragraph upperLeftParagraphFirstTableFooter = footer_first.Tables[0].Rows[0].Cells[0].Paragraphs[0];
                upperLeftParagraphFirstTableFooter.Append("Company Name - DocX Corporation");
                #endregion



                #region Company Logo in Header in Invisible Table
                // Insert Table into First Header - Create a new Table with 2 columns and 1 rows.
                Novacode.Table footer_second_table = footer_odd.InsertTable(1, 2);
                footer_second_table.Design = TableDesign.None;
                footer_second_table.AutoFit = AutoFit.Window;
                // Get the upper right Paragraph in the layout_table.
                Paragraph upperRightParagraphSecondTableFooter = footer_second_table.Rows[0].Cells[1].Paragraphs[0];
                // Insert this template logo into the upper right Paragraph of Table.
                upperRightParagraphSecondTableFooter.AppendPicture(logo.CreatePicture());
                upperRightParagraphSecondTableFooter.Alignment = Alignment.right;

                // Get the upper left Paragraph in the layout_table.
                Paragraph upperLeftParagraphSecondTableFooter = footer_second_table.Rows[0].Cells[0].Paragraphs[0];
                upperLeftParagraphSecondTableFooter.Append("Company Name - DocX Corporation");
                #endregion

                // Save all changes to this document.
                document.Save();

            }// Release this document from memory.
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            using (DocX document = DocX.Create(@"c://pdf/HeadersAndFooters.docx"))
            {
                //向文档中添加页眉页脚
                document.AddHeaders();
                document.AddFooters();

                //首页是否不同(页眉/页脚)
                document.DifferentFirstPage = false;

                //是否区分奇偶数页
                document.DifferentOddAndEvenPages = true;

                Header header_first = document.Headers.first;
                Header header_odd = document.Headers.odd;
                Header header_even = document.Headers.even;
                
                Footer footer_first = document.Footers.first;
                Footer footer_odd = document.Footers.odd;
                Footer footer_even = document.Footers.even;
                
                Paragraph p0 = header_first.Paragraphs[0];
                p0.Append("首页页眉").Bold();
                p0.Alignment = Alignment.center;

                Paragraph p3 = footer_first.Paragraphs[0];
                p3.Append("首页页脚").Bold();
                p3.Alignment = Alignment.center;
                
                Paragraph p1 = header_odd.Paragraphs[0];
                
                p1.Append("奇数页眉").Bold();               
                p1.Alignment = Alignment.center;

                //页脚插入页码
                Paragraph p4 = footer_odd.Paragraphs[0];
                //p4.Append("奇数页脚").Bold();
                p4.Alignment = Alignment.center;
                p4.Append("第");
                p4.AppendPageNumber(PageNumberFormat.normal);
                p4.Append("页,共");
                p4.AppendPageCount(PageNumberFormat.normal);
                p4.Append("页");

                Paragraph p2 = header_even.Paragraphs[0];
                p2.Append("偶数页眉").Bold();
                //p2.InsertText("偶数页眉");
                p2.Alignment = Alignment.center;

                Paragraph p5 = footer_even.Paragraphs[0];
                p5.Append("偶数页脚").Bold();
                p5.Alignment = Alignment.center;

                Paragraph p6 = document.InsertParagraph();
                for (int i = 0; i < 100; i++)
                {
                    p6.AppendLine("这是第一页");
                }

                // Create a second page to show that the first page has its own header and footer.
                p6.InsertPageBreakAfterSelf();
                
                // Insert a Paragraph after the page break.
                Paragraph p7 = document.InsertParagraph();
                p7.AppendLine("这是第二页");

                // Create a third page to show that even and odd pages have different headers and footers.
                p7.InsertPageBreakAfterSelf();

                // Insert a Paragraph after the page break.
                Paragraph p8 = document.InsertParagraph();
                p8.AppendLine("这是第三页");

                document.Save();
            }
        }

        protected void Button7_Click(object sender, EventArgs e)
        {
            using (DocX document = DocX.Create(@"C://PDF/DocumentsWithListsFontChange.docx"))
            {

                foreach (FontFamily oneFontFamily in FontFamily.Families)
                {

                    FontFamily fontFamily = oneFontFamily;
                    double fontSize = 15;

                    // created numbered lists 
                    var numberedList = document.AddList("First List Item.", 0, Novacode.ListItemType.Numbered, 1);
                    document.AddListItem(numberedList, "First sub list item", 1);
                    document.AddListItem(numberedList, "Second List Item.");
                    document.AddListItem(numberedList, "Third list item.");
                    document.AddListItem(numberedList, "Nested item.", 1);
                    document.AddListItem(numberedList, "Second nested item.", 1);

                    // created bulleted lists

                    var bulletedList = document.AddList("First Bulleted Item.", 0, Novacode.ListItemType.Bulleted);
                    document.AddListItem(bulletedList, "Second bullet item");
                    document.AddListItem(bulletedList, "Sub bullet item", 1);
                    document.AddListItem(bulletedList, "Second sub bullet item", 1);
                    document.AddListItem(bulletedList, "Third bullet item");

                    document.InsertList(bulletedList);
                    document.InsertList(numberedList, fontFamily, fontSize);

                }
                // Save this document.
                document.Save();
            }
        }

        protected void Button8_Click(object sender, EventArgs e)
        {
            using (DocX document = DocX.Create(@"C://PDF/DocumentMargins.docx"))
            {

                // Create a float var that contains doc Margins properties.
                float leftMargin = document.MarginLeft;
                float rightMargin = document.MarginRight;
                float topMargin = document.MarginTop;
                float bottomMargin = document.MarginBottom;
                // Modify using your own vars.
                leftMargin = 195F;
                rightMargin = 45F;
                topMargin = 50F;
                bottomMargin = 180F;

                // Or simply work the margins by setting the property directly. 
                document.MarginLeft = leftMargin;
                document.MarginRight = rightMargin;
                document.MarginTop = topMargin;
                document.MarginBottom = bottomMargin;

                // created bulleted lists

                var bulletedList = document.AddList("First Bulleted Item.", 0, Novacode.ListItemType.Bulleted);
                document.AddListItem(bulletedList, "Second bullet item");
                document.AddListItem(bulletedList, "Sub bullet item", 1);
                document.AddListItem(bulletedList, "Second sub bullet item", 1);
                document.AddListItem(bulletedList, "Third bullet item");


                document.InsertList(bulletedList);

                // Save this document.
                document.Save();

                Console.WriteLine("\tCreated: docs\\DocumentMargins.docx\n");
            }
        }

        protected void Button9_Click(object sender, EventArgs e)
        {
            using (DocX document = DocX.Create(@"C://PDF/HyperlinksImagesTablesWithLists.docx"))
            {
                // Add a hyperlink into the document.
                Hyperlink link = document.AddHyperlink("link", new Uri("http://www.baidu.com"));

                // created numbered lists 
                var numberedList = document.AddList("First List Item.", 0, Novacode.ListItemType.Numbered, 1);
                document.AddListItem(numberedList, "First sub list item", 1);
                document.AddListItem(numberedList, "Second List Item.");
                document.AddListItem(numberedList, "Third list item.");
                document.AddListItem(numberedList, "Nested item.", 1);
                document.AddListItem(numberedList, "Second nested item.", 1);

                // created bulleted lists

                var bulletedList = document.AddList("First Bulleted Item.", 0, Novacode.ListItemType.Bulleted);
                document.AddListItem(bulletedList, "Second bullet item");
                document.AddListItem(bulletedList, "Sub bullet item", 1);
                document.AddListItem(bulletedList, "Second sub bullet item", 1);
                document.AddListItem(bulletedList, "Third bullet item");


                // Add a Table into the document.
                Novacode.Table table = document.AddTable(2, 2);
                table.Design = TableDesign.ColorfulGridAccent2;
                table.Alignment = Alignment.center;
                table.Rows[0].Cells[0].Paragraphs[0].Append("1");
                table.Rows[0].Cells[1].Paragraphs[0].Append("2");
                table.Rows[1].Cells[0].Paragraphs[0].Append("3");
                table.Rows[1].Cells[1].Paragraphs[0].Append("4");

                Row newRow = table.InsertRow(table.Rows[1]);
                newRow.ReplaceText("4", "5");

                // Add an image into the document.    
                Novacode.Image image = document.AddImage(Server.MapPath("images/Image.jpg"));

                // Create a picture (A custom view of an Image).
                Picture picture = image.CreatePicture();
                picture.Width = 100;
                picture.Height = 100;
                picture.Rotation = 10;
                picture.SetPictureShape(BasicShapes.cube);

                // Insert a new Paragraph into the document.
                Paragraph title = document.InsertParagraph().Append("Test").FontSize(20).Font(new FontFamily("Comic Sans MS"));
                title.Alignment = Alignment.center;



                // Insert a new Paragraph into the document.
                Paragraph p1 = document.InsertParagraph();

                // Append content to the Paragraph
                p1.AppendLine("This line contains a ").Append("bold").Bold().Append(" word.");
                p1.AppendLine("Here is a cool ").AppendHyperlink(link).Append(".");
                p1.AppendLine();
                p1.AppendLine("Check out this picture ").AppendPicture(picture).Append(" its funky don't you think?");
                p1.AppendLine();
                p1.AppendLine("Can you check this Table of figures for me?");
                p1.AppendLine();

                // Insert the Table after Paragraph 1.
                p1.InsertTableAfterSelf(table);

                // Insert a new Paragraph into the document.
                Paragraph p2 = document.InsertParagraph();

                // Append content to the Paragraph.
                p2.AppendLine("Is it correct?");
                p2.AppendLine();
                p2.AppendLine("Adding bullet list below: ");

                document.InsertList(bulletedList);

                // Adding another paragraph to add table and bullet list after it
                Paragraph p3 = document.InsertParagraph();
                p3.AppendLine();
                p3.AppendLine("Adding another table...");

                // Adding another table
                Novacode.Table table1 = document.AddTable(2, 2);
                table1.Design = TableDesign.ColorfulGridAccent2;
                table1.Alignment = Alignment.center;
                table1.Rows[0].Cells[0].Paragraphs[0].Append("1");
                table1.Rows[0].Cells[1].Paragraphs[0].Append("2");
                table1.Rows[1].Cells[0].Paragraphs[0].Append("3");
                table1.Rows[1].Cells[1].Paragraphs[0].Append("4");

                Paragraph p4 = document.InsertParagraph();
                p4.InsertTableBeforeSelf(table1);

                p4.AppendLine();


                // Insert numbered list after table
                Paragraph p5 = document.InsertParagraph();
                p5.AppendLine("Adding numbered list below: ");
                p5.AppendLine();
                document.InsertList(numberedList);
                // Save this document.
                document.Save();
            }
        }

        protected void Button10_Click(object sender, EventArgs e)
        {
            using (DocX document = DocX.Create(@"C://PDF/HyperlinksImagesTables.docx"))
            {
                // Add a hyperlink into the document.
                Hyperlink link = document.AddHyperlink("link", new Uri("http://www.baidu.com"));

                // Add a Table into the document.
                Novacode.Table table = document.AddTable(2, 2);
                table.Design = TableDesign.ColorfulGridAccent2;
                table.Alignment = Alignment.center;
                table.Rows[0].Cells[0].Paragraphs[0].Append("1");
                table.Rows[0].Cells[1].Paragraphs[0].Append("2");
                table.Rows[1].Cells[0].Paragraphs[0].Append("3");
                table.Rows[1].Cells[1].Paragraphs[0].Append("4");

                Row newRow = table.InsertRow(table.Rows[1]);
                newRow.ReplaceText("4", "5");

                // Add an image into the document.    

                Novacode.Image image = document.AddImage(Server.MapPath( @"images\Image.jpg"));

                // Create a picture (A custom view of an Image).
                Picture picture = image.CreatePicture();
                picture.Rotation = 10;
                picture.SetPictureShape(BasicShapes.cube);

                // Insert a new Paragraph into the document.
                Paragraph title = document.InsertParagraph().Append("Test").FontSize(20).Font(new FontFamily("Comic Sans MS"));
                title.Alignment = Alignment.center;

                // Insert a new Paragraph into the document.
                Paragraph p1 = document.InsertParagraph();

                // Append content to the Paragraph
                p1.AppendLine("This line contains a ").Append("bold").Bold().Append(" word.");
                p1.AppendLine("Here is a cool ").AppendHyperlink(link).Append(".");
                p1.AppendLine();
                p1.AppendLine("Check out this picture ").AppendPicture(picture).Append(" its funky don't you think?");
                p1.AppendLine();
                p1.AppendLine("Can you check this Table of figures for me?");
                p1.AppendLine();

                // Insert the Table after Paragraph 1.
                p1.InsertTableAfterSelf(table);

                // Insert a new Paragraph into the document.
                Paragraph p2 = document.InsertParagraph();

                // Append content to the Paragraph.
                p2.AppendLine("Is it correct?");

                // Save this document.
                document.Save();
            }
        }

        protected void Button11_Click(object sender, EventArgs e)
        {
            using (DocX document = DocX.Create(@"C://PDF/RightToLeft.docx"))
            {
                Paragraph p = document.InsertParagraph("Hello World.");
                p.Direction = Direction.RightToLeft;

                // You don't need to manually set the text direction foreach Paragraph, you can just call this function.
                document.SetDirection(Direction.RightToLeft);
                
                // Save all changes made to this document.
                document.Save();
            }
        }

        protected void Button12_Click(object sender, EventArgs e)
        {
            using (DocX document = DocX.Create(@"C://PDF/Indentation.docx"))
            {
                // Create a new Paragraph.
                Paragraph p = document.InsertParagraph("Line 1\nLine 2\nLine 3");

                // Indent only the first line of the Paragraph.
                p.IndentationFirstLine = 1.0f;


                // Save all changes made to this document.
                document.Save();
            }
        }

        protected void Button13_Click(object sender, EventArgs e)
        {
            using (DocX docX = DocX.Load("C://PDF/DocumentWithBookmarks.docx"))
            {
                foreach (Bookmark bookmark in docX.Bookmarks)
                    Console.WriteLine("\t\tFound bookmark {0}", bookmark.Name);

                // Replace bookmars content
                docX.Bookmarks["bmkNoContent"].SetText("Here there was a bookmark");
                docX.Bookmarks["bmkContent"].SetText("Here there was a bookmark with a previous content");
                docX.Bookmarks["bmkFormattedContent"].SetText("Here there was a formatted bookmark");

                docX.SaveAs(@"C://PDF/BookmarksReplaceTextOfBookmarkKeepingFormat.docx");
            }
        }

        protected void Button14_Click(object sender, EventArgs e)
        {
            using (var document = DocX.Create(@"C://PDF/Bookmarks.docx"))
            {
                var paragraph = document.InsertBookmark("firstBookmark");

                var paragraph2 = document.InsertParagraph("This is a paragraph which contains a ");
                paragraph2.AppendBookmark("secondBookmark");
                paragraph2.Append("bookmark");

                paragraph2.InsertAtBookmark("handy ", "secondBookmark");

                document.Save();

            }
        }

        protected void Button15_Click(object sender, EventArgs e)
        {
            using (DocX document = DocX.Create(@"C://PDF/DocumentHeading.docx"))
            {
                string text = string.Format("这是一级标题");

                Paragraph p = document.InsertParagraph();
                p.Append(text).Heading(HeadingType.Heading1);
                document.Save();
            }
        }

        protected void Button16_Click(object sender, EventArgs e)
        {
            using (DocX document = DocX.Create(@"C://PDF/Equations.docx"))
            {
                // Insert first Equation in this document.
                Paragraph pEquation1 = document.InsertEquation("x = y+z");

                // Insert second Equation in this document and add formatting.
                Paragraph pEquation2 = document.InsertEquation("x = (y+z)/t").FontSize(18).Color(Color.Blue);

                // Save this document to disk.
                document.Save();

            }
        }

        protected void Button17_Click(object sender, EventArgs e)
        {
            using (DocX document = DocX.Create(@"C://PDF/3DChart.docx"))
            {
                // Create chart.
                BarChart c = new BarChart();
                c.View3D = true;

                // Create data.
                List<ChartData> company1 = ChartData.CreateCompanyList1();
                List<ChartData> company2 = ChartData.CreateCompanyList2();

                // Create and add series
                Series s = new Series("微软");
                s.Color = Color.GreenYellow;
                s.Bind(company1, "Mounth", "Money");
                c.AddSeries(s);

                Series s2 = new Series("苹果");
                s2.Color = Color.Red;
                s2.Bind(company2, "Mounth", "Money");
                c.AddSeries(s2);
                // Insert chart into document
                document.InsertParagraph("3D柱状图").FontSize(20);
                document.InsertChart(c);
                document.Save();
            }
        }

        protected void Button18_Click(object sender, EventArgs e)
        {
            using (DocX document = DocX.Create(@"C://PDF/LineChart.docx"))
            {
                // Create chart.
                LineChart c = new LineChart();
                c.AddLegend(ChartLegendPosition.Bottom, false);

                // Create data.
                List<ChartData> company1 = ChartData.CreateCompanyList1();
                List<ChartData> company2 = ChartData.CreateCompanyList2();

                // Create and add series
                Series s1 = new Series("微软");
                s1.Color = Color.GreenYellow;
                s1.Bind(company1, "Mounth", "Money");
                c.AddSeries(s1);
                Series s2 = new Series("苹果");
                s2.Bind(company2, "Mounth", "Money");
                c.AddSeries(s2);

                // Insert chart into document
                document.InsertParagraph("折线图").FontSize(20);
                document.InsertChart(c);
                document.Save();
            }
        }

        protected void Button19_Click(object sender, EventArgs e)
        {
            // Create new document. 
            using (DocX document = DocX.Create(@"C://PDF/PieChart.docx"))
            {
                // Create chart.
                PieChart c = new PieChart();
                c.AddLegend(ChartLegendPosition.Bottom, false);
                
                // Create data.
                List<ChartData> company2 = ChartData.CreateCompanyList2();

                // Create and add series
                Series s = new Series("苹果");
                s.Bind(company2, "Mounth", "Money");
                c.AddSeries(s);

                // Insert chart into document
                document.InsertParagraph("饼状图").FontSize(20);
                document.InsertChart(c);
                document.Save();
            }
        }

        protected void Button20_Click(object sender, EventArgs e)
        {
            using (DocX document = DocX.Create(@"C://PDF/BarChart.docx"))
            {
                // Create chart.
                BarChart c = new BarChart();
                c.BarDirection = BarDirection.Column;
                c.BarGrouping = BarGrouping.Standard;
                c.GapWidth = 400;
                c.AddLegend(ChartLegendPosition.Bottom, false);

                // Create data.
                List<ChartData> company1 = ChartData.CreateCompanyList1();
                List<ChartData> company2 = ChartData.CreateCompanyList2();

                // Create and add series
                Series s1 = new Series("微软");
                s1.Color = Color.GreenYellow;
                s1.Bind(company1, "Mounth", "Money");
                c.AddSeries(s1);
                Series s2 = new Series("苹果");
                s2.Bind(company2, "Mounth", "Money");
                c.AddSeries(s2);

                // Insert chart into document
                document.InsertParagraph("柱状图").FontSize(20);
                document.InsertChart(c);
                document.Save();
            }
        }

        protected void Button21_Click(object sender, EventArgs e)
        {
            DocX doc = DocX.Load("C://PDF/JL.docx");
            Novacode.Table tb1= doc.Tables[0];
            Paragraph p1=doc.Paragraphs[0];
            //Novacode.Image img = doc.Images[0];
            p1.ReplaceText("旧串","新串");
            //img.CreatePicture().Remove();
            Novacode.Image image = doc.AddImage(Server.MapPath(@"images\Image.jpg"));
            Picture picture = image.CreatePicture();
            picture.Width = 100;
            picture.Height = 140;
            picture.FlipHorizontal = false;//是否水平翻转
            picture.FlipVertical = false;//是否垂直翻转
            
            tb1.Rows[0].Cells[1].Paragraphs.First().Alignment = Alignment.left;
            tb1.Rows[0].Cells[1].Paragraphs.First().AppendPicture(picture);

            tb1.Rows[1].Cells[1].Paragraphs.First().Append("张三");
            tb1.Rows[1].Cells[3].Paragraphs.First().Append("男");
            tb1.Rows[1].Cells[5].Paragraphs.First().Append("未婚");
            tb1.Rows[2].Cells[1].Paragraphs.First().Append("25");
            tb1.Rows[2].Cells[3].Paragraphs.First().Append("河南");
            tb1.Rows[2].Cells[5].Paragraphs.First().Append("健康");
            tb1.Rows[3].Cells[1].Paragraphs.First().Append("党员");
            tb1.Rows[3].Cells[3].Paragraphs.First().Append("汉");
            tb1.Rows[3].Cells[5].Paragraphs.First().Append("河南新乡");

            tb1.Rows[4].Cells[1].Paragraphs.First().Alignment = Alignment.left;
            tb1.Rows[4].Cells[1].Paragraphs.First().Append(".NET工程师");

            tb1.Rows[6].Cells[1].Paragraphs.First().Alignment = Alignment.left;
            tb1.Rows[6].Cells[1].Paragraphs.First().Append("17703775542");

            tb1.Rows[6].Cells[3].Paragraphs.First().Alignment = Alignment.left;
            tb1.Rows[6].Cells[3].Paragraphs.First().Append("940271306@qq.com");
            tb1.Rows[8].Cells[1].Paragraphs.First().Append("本科");
            tb1.Rows[9].Cells[1].Paragraphs.First().Append("2012-2016南阳师范学院");
            tb1.Rows[11].Cells[1].Paragraphs.First().Append("暂无工作经验");
            tb1.Rows[13].Cells[1].Paragraphs.First().Append("英语四级");
            tb1.Rows[13].Cells[3].Paragraphs.First().Append("四级网络工程师");
            tb1.Rows[13].Cells[5].Paragraphs.First().Append("二级甲等");

            tb1.Rows[14].Cells[1].Paragraphs.First().Alignment = Alignment.left;
            tb1.Rows[14].Cells[1].Paragraphs.First().Append("暂无其他技能");

            tb1.Rows[16].Cells[0].Paragraphs.First().Append("暂无自我评价");
            doc.SaveAs("C://PDF/JL2.docx");
        }

        protected void Button22_Click(object sender, EventArgs e)
        {
            // 创建新文档
            using (var document = DocX.Create("C://PDF/11.docx"))
            {
                // 这个文档添加页眉和页脚。
                document.AddHeaders();
                document.AddFooters();
                // 强制第一个页面有一个不同的头和脚。
                document.DifferentFirstPage = true;
                // 奇偶页页眉页脚不同
                document.DifferentOddAndEvenPages = true;
                // 获取本文档的第一个、奇数和甚至是头文件。
                Header headerFirst = document.Headers.first;
                Header headerOdd = document.Headers.odd;
                Header headerEven = document.Headers.even;
                // 获取此文档的第一个、奇数和甚至脚注。
                Footer footerFirst = document.Footers.first;
                Footer footerOdd = document.Footers.odd;
                Footer footerEven = document.Footers.even;
                // 将一段插入到第一个头。
                Paragraph p0 = headerFirst.InsertParagraph();
                p0.Append("Hello First Header.").Bold();
                // 在奇数头中插入一个段落。
                Paragraph p1 = headerOdd.InsertParagraph();
                p1.Append("Hello Odd Header.").Bold();
                // 插入一个段落到偶数头中。
                Paragraph p2 = headerEven.InsertParagraph();
                p2.Append("Hello Even Header.").Bold();
                // 将一段插入到第一个脚注中。
                Paragraph p3 = footerFirst.InsertParagraph();
                p3.Append("Hello First Footer.").Bold();
                // 在奇数脚注中插入一个段落。
                Paragraph p4 = footerOdd.InsertParagraph();
                p4.Append("Hello Odd Footer.").Bold();
                // 插入一个段落到偶数头中。
                Paragraph p5 = footerEven.InsertParagraph();
                p5.Append("Hello Even Footer.").Bold();
                // 在文档中插入一个段落。
                Paragraph p6 = document.InsertParagraph();
                p6.AppendLine("Hello First page.");
                // 创建一个第二个页面，显示第一个页面有自己的头和脚。
                p6.InsertPageBreakAfterSelf();
                // 在页面中断后插入一段。
                Paragraph p7 = document.InsertParagraph();
                p7.AppendLine("Hello Second page.");
                // 创建三分之一页面显示，奇偶页不同的页眉和页脚。
                p7.InsertPageBreakAfterSelf();
                // 在页面中断后插入一段。
                Paragraph p8 = document.InsertParagraph();
                p8.AppendLine("Hello Third page.");
                // 将属性保存入文档
                document.Save();
    
            }
        }
    }

    public class ChartData
    {
        public String Mounth { get; set; }
        public Double Money { get; set; }

        public static List<ChartData> CreateCompanyList1()
        {
            List<ChartData> company1 = new List<ChartData>();
            company1.Add(new ChartData() { Mounth = "1月", Money = 100 });
            company1.Add(new ChartData() { Mounth = "2月", Money = 120 });
            company1.Add(new ChartData() { Mounth = "3月", Money = 140 });
            return company1;
        }
        public static List<ChartData> CreateCompanyList2()
        {
            List<ChartData> company2 = new List<ChartData>();
            company2.Add(new ChartData() { Mounth = "1月", Money = 80 });
            company2.Add(new ChartData() { Mounth = "2月", Money = 160 });
            company2.Add(new ChartData() { Mounth = "3月", Money = 130 });
            return company2;
        }
    }
}